# coding:utf-8
"""
系统标准库
"""
import os
import time

"""
三方库
"""
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
import pytest

"""
自定义库
"""
import setting

chrome_options = webdriver.ChromeOptions()
# chrome_options.add_argument('--headless')  # 无界面启动
# chrome_options.add_argument(
#     '--user-data-dir=C:\\Users\\wanshen\\AppData\\Local\\Google\\Chrome\\User Data\\Default')  # 使浏览器加载个人配置信息
# chrome_options.add_argument('--disable-gpu') # 解决定位问题

browser = webdriver.Chrome(setting.WEBDRIVERURI, chrome_options=chrome_options)
browser.implicitly_wait(10)  # 设置页面等待时间为10秒
mainUrl = 'https://yun.yemaogj.com/Login'
browser.maximize_window()  # 最大化浏览器
# print(browser.get_window_rect())

browser.get(mainUrl)
# print(f'browser text = {browser.page_source}')
logintitle = EC.title_contains(u'夜猫管理平台-登陆')  # 标题是否包含
print(logintitle(browser))

browser.find_element_by_id('login_account').send_keys("funtest01")  # 获取到登录框
time.sleep(1)
# browser.set_window_size(480, 800)  # 设置浏览器窗口大小
browser.find_element_by_css_selector('[class="lg_input m-b-12"]').send_keys('123456')  # #login_pwd
browser.find_element_by_css_selector('[class="lg_input m-b-12"]').send_keys(Keys.ENTER)
browser.find_element_by_xpath('//*[@id="login_pwd"]').send_keys('123123')  # 使用xpath 寻找密码输入框

# browser.find_element_by_class_name('lg_btn').click()
# browser.minimize_window()  # 最小化浏览器
# print(browser.get_window_rect())
# time.sleep(1)
# print(browser.title + "-------" + str(browser.get_cookies()))
# browser.back()  # 页面后退
# time.sleep(1)
# print(browser.title + "---------" + str(browser.get_cookies()))
# browser.forward()
# time.sleep(1)
# print(browser.title)
print(browser.window_handles)
# browser.switch_to_window()
time.sleep(3)
browser.close()
